﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ConsoleApplication2.Models;

namespace ConsoleApplication2.Controllers
{
    public class VenController : Controller
    {
        private HMS909Context db = new HMS909Context();

        //
        // GET: /Ven/

        public ActionResult Index()
        {
         
            return View(db.Vends.ToList());
        }

        //
        // GET: /Ven/Details/5

        public ActionResult Details(string id = null)
        {
            Vend vend = db.Vends.Find(id);
            if (vend == null)
            {
                return HttpNotFound();
            }
            return View(vend);
        }

        //
        // GET: /Ven/Create

        public ActionResult Create()
        {
            ViewBag.ACCT = new SelectList(db.Accts, "ACCT1", "DESC");
            ViewBag.APACCT = new SelectList(db.Accts, "ACCT1", "DESC");
            ViewBag.under_collection_acct = new SelectList(db.Accts, "ACCT1", "DESC");
            ViewBag.CURRENCY = new SelectList(db.currencies, "ID", "DESCRIP");
            ViewBag.SPECIALTY = new SelectList(db.Specialties, "ID", "NAME");
            return View();
        }

        //
        // POST: /Ven/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(Vend vend)
        {
            if (ModelState.IsValid)
            {
                db.Vends.Add(vend);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ACCT = new SelectList(db.Accts, "ACCT1", "DESC", vend.ACCT);
            ViewBag.APACCT = new SelectList(db.Accts, "ACCT1", "DESC", vend.APACCT);
            ViewBag.under_collection_acct = new SelectList(db.Accts, "ACCT1", "DESC", vend.under_collection_acct);
            ViewBag.CURRENCY = new SelectList(db.currencies, "ID", "DESCRIP", vend.CURRENCY);
            ViewBag.SPECIALTY = new SelectList(db.Specialties, "ID", "NAME", vend.SPECIALTY);
            return View(vend);
        }

        //
        // GET: /Ven/Edit/5

        public ActionResult Edit(string id = null)
        {
            Vend vend = db.Vends.Find(id);
            if (vend == null)
            {
                return HttpNotFound();
            }
            ViewBag.ACCT = new SelectList(db.Accts, "ACCT1", "DESC", vend.ACCT);
            ViewBag.APACCT = new SelectList(db.Accts, "ACCT1", "DESC", vend.APACCT);
            ViewBag.under_collection_acct = new SelectList(db.Accts, "ACCT1", "DESC", vend.under_collection_acct);
            ViewBag.CURRENCY = new SelectList(db.currencies, "ID", "DESCRIP", vend.CURRENCY);
            ViewBag.SPECIALTY = new SelectList(db.Specialties, "ID", "NAME", vend.SPECIALTY);
            return View(vend);
        }

        //
        // POST: /Ven/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Vend vend)
        {
            if (ModelState.IsValid)
            {
                db.Entry(vend).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.ACCT = new SelectList(db.Accts, "ACCT1", "DESC", vend.ACCT);
            ViewBag.APACCT = new SelectList(db.Accts, "ACCT1", "DESC", vend.APACCT);
            ViewBag.under_collection_acct = new SelectList(db.Accts, "ACCT1", "DESC", vend.under_collection_acct);
            ViewBag.CURRENCY = new SelectList(db.currencies, "ID", "DESCRIP", vend.CURRENCY);
            ViewBag.SPECIALTY = new SelectList(db.Specialties, "ID", "NAME", vend.SPECIALTY);
            return View(vend);
        }

        //
        // GET: /Ven/Delete/5

        public ActionResult Delete(string id = null)
        {
            Vend vend = db.Vends.Find(id);
            if (vend == null)
            {
                return HttpNotFound();
            }
            return View(vend);
        }

        //
        // POST: /Ven/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(string id)
        {
            Vend vend = db.Vends.Find(id);
            db.Vends.Remove(vend);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}